﻿//
// File:    AppController.cs
// Project: Traveler 0.3.x (A Windows file explorer)
//
// Copyright 2011-2012 Kasey Osborn (Kasewick@gmail.com)
// Ms-PL license - Use and redistribute freely
//

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using AssemblyInfo;
using TravViewed;
using ProgressViewed;
using Progress;
using Trav;

namespace WinController
{
    /// <summary>
    /// Define the Controller component of the Strict MVC pattern for the Traveler project.
    /// This component defines the user interface, processes user input, and dispatches that
    /// input to the model.
    /// </summary>
    public partial class AppController : Form
    {
        private string[] args;
        private IViewFactory viewFactory;
        private TravModel model;
        internal bool SupressStatusUpdates = false;
        internal Font DetailFont { get; private set; }

        // TODO find a better home for column enumerations
        static internal readonly int ColumnType = -2;
        static internal readonly int ColumnSelection = -1;
        static internal readonly int ColumnBaseName = 0;
        static internal readonly int ColumnSize = 1;
        static internal readonly int ColumnRelativePathName = 2;
        static internal readonly int ColumnHash = 3;
        static internal readonly int ColumnFullPathName = 4;
        static internal readonly int ColumnModifyDate = 5;


        internal AppController (string[] args, IViewFactory viewFactory)
        {
            this.args = args;
            this.viewFactory = viewFactory;
            this.DetailFont = new Font ("Courier New", 10, FontStyle.Bold);
            InitializeComponent ();
        }

        protected override void Dispose (bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                    components.Dispose();
                model.Dispose();
            }

            base.Dispose (disposing);
        }


        private void AppController_Shown (object sender, EventArgs e)
        {
            // Set title bar text.
            Text = About.Title;

            // Create the application's model.
            model = new TravModel (args.Length == 0? null : args[0]);

            // Create the views while injecting them into the model.
            viewFactory.MakeAll (this, model);

            if (model.Arg != null)
                model.OpenRootAsync (model.Arg);
        }
    }
}
